import {
	db
} from "../../utils/dbhelp1.js"

let logincheck = function() {
	return new Promise((resolve,reject) =>{
		let openid = uni.getStorageSync('openid')
		db('user').where({
				_openid: openid
			}).get()
			.then((res) => {
			console.log(res.data)
			if(res.data.length){
				resolve({
					login: true,
					data: res.data
				})
			}else{
				resolve({
					login: false,
					data: res.data
				})
			}
				
		})
	})
}

let addUser = function(data){
	return new Promise((resolve,reject) =>{
		db('user').add({
			data
		})
		.then((res) =>{
			console.log(res,123)
			resolve(true)
		})
	})
}


module.exports = {
	logincheck,
	addUser
}